package com.blueocean_health.care.management.controller.app;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.blueocean_health.care.management.common.LocalManager;
import com.blueocean_health.care.management.common.base.string.StringUtils;
import com.blueocean_health.care.management.domain.base.SysResult;
import com.blueocean_health.care.management.domain.base.UserPatient;
import com.blueocean_health.care.management.domain.base.UserPhoneCode;
import com.blueocean_health.care.management.domain.dto.UserPatientDto;
import com.blueocean_health.care.management.em.LocalManagerType;
import com.blueocean_health.care.management.service.UserPatientService;

/**
 * 负责人下拉框 接口    2017年8月22日15:37:01
 * @author wuyanli
 *
 */
@RestController
@RequestMapping("app/user-patient")
public class UserPatientController {
	
	@Resource
	private UserPatientService patientService;

	@RequestMapping(value = "/login")
	public SysResult login(@RequestBody(required = false) UserPhoneCode user) {
		if(StringUtils.isEmpty(user.getPhone())){
			return SysResult.error("手机号不能为空");
		}else if(StringUtils.isEmpty(user.getPhoneCode())){
			return SysResult.error("验证码不能为空");
		}else{
			UserPatientDto userInfo = patientService.getUserInfo(user);
			if(userInfo==null){
				return SysResult.error("手机号或验证码错误");
			}
			return SysResult.ok(userInfo);
		}
	}
	/**
	 * 退出登录页面走token验证  2018年3月28日09:47:17
	 * @param patient
	 * @return
	 */
	@RequestMapping("/getUserPhone")
	public SysResult getUserPhone(){
		 UserPatient val = LocalManager.getVal(LocalManagerType.USER_APP);
//		 String phone = val.getPhone();
	     return SysResult.ok(val);
	}
	
	@RequestMapping("/phonecode")
	public SysResult getPhoneCode(@RequestBody UserPhoneCode patient){
		int addPhoneCode = patientService.addPhoneCode(patient);
		if(addPhoneCode <= 0){
			return SysResult.error("获取验证码失败");
		}
		return SysResult.ok( "获取成功");
	}
	
}
